LEADTOOLS Annotations (Leadtools.Annotations assembly)

Save(String,AnnContainer[],AnnCodecsFormat) Method

Show in webframe
Example 





The output file name.
An array of AnnContainer containing the objects to be saved.
An AnnCodecsFormat value that specifies the annotation format to use when saving.
Saves an array of AnnContainer to a multipage annotation disk file
Syntax
public void Save( 
   string fileName,
   AnnContainer[] containers,
   AnnCodecsFormat format
)
'Declaration
 
Public Overloads Sub Save( _
   ByVal fileName As String, _
   ByVal containers() As AnnContainer, _
   ByVal format As AnnCodecsFormat _
) 
'Usage
 
Dim instance As AnnCodecs
Dim fileName As String
Dim containers() As AnnContainer
Dim format As AnnCodecsFormat
 
instance.Save(fileName, containers, format)

            

            
public:
void Save( 
   String^ fileName,
   array<AnnContainer^>^ containers,
   AnnCodecsFormat format
) 

Parameters

fileName
The output file name.
containers
An array of AnnContainer containing the objects to be saved.
format
An AnnCodecsFormat value that specifies the annotation format to use when saving.
Remarks

This method saves the entire array of AnnContainer as a multipage annotation file, with each page corresponding to one of the AnnContainer. If fileName already exists, it will be overwritten. If containers contain many AnnContainer, then this method will create the multipage annotation file much faster than repeated calls to Save(String,AnnContainer,AnnCodecsFormat,Int32,AnnCodecsSavePageMode)

This method only supports the AnnCodecsFormat.Xml format. All other AnnCodecsFormat are not supported.

For more information, refer to Annotation Files.

Example
Copy Code  
Imports Leadtools
Imports Leadtools.Annotations
Imports Leadtools.Codecs
Imports Leadtools.WinForms

Public Sub AnnCodecs_Save2()
    ' create three  annotation containers
    ' The first container contains a rectangle object
    Dim container0 As New AnnContainer()
    Dim rectObj As New AnnRectangleObject()
    rectObj.Bounds = New AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel)
    rectObj.Pen = New AnnPen(Color.Blue, New AnnLength(1, AnnUnit.Pixel))
    rectObj.Brush = Nothing
    container0.Objects.Add(rectObj)

    ' The second container contains a line object
    Dim container1 As New AnnContainer()
    Dim lineObj As New AnnLineObject()
    lineObj.StartPoint = New AnnPoint(100, 100, AnnUnit.Pixel)
    lineObj.EndPoint = New AnnPoint(200, 200, AnnUnit.Pixel)
    lineObj.Pen = New AnnPen(Color.Red, New AnnLength(1, AnnUnit.Pixel))
    container1.Objects.Add(lineObj)

    ' The third container contains a ellipse object
    Dim container2 As New AnnContainer()
    Dim ellipseObj As New AnnEllipseObject()
    ellipseObj.Bounds = New AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel)
    ellipseObj.Pen = New AnnPen(Color.Blue, New AnnLength(1, AnnUnit.Pixel))
    ellipseObj.Brush = Nothing
    container2.Objects.Add(ellipseObj)

    ' create a file to save both annotation containers
    Dim annFileName As String = Path.GetTempFileName()

    ' create a new AnnCodecs class
    Dim codecs As New AnnCodecs()

    ' save both AnnContainers into the stream
    codecs.Save(annFileName, container0, AnnCodecsFormat.Xml, 1, AnnCodecsSavePageMode.Overwrite)
    codecs.Save(annFileName, container1, AnnCodecsFormat.Xml, 2, AnnCodecsSavePageMode.Insert)

    ' Now load both containers from the stream, and verify that there are two containers
    Dim containersTwo() As AnnContainer = codecs.Load(annFileName)
    MessageBox.Show(String.Format("After Load: there should be 2 containers.  Total number of containers: {0}", containersTwo.Length))

    ' Add another container, and save to the stream
    Dim containersNew(containersTwo.Length) As AnnContainer
    Array.Copy(containersTwo, containersNew, containersTwo.Length)
    containersNew(2) = container2

    codecs.Save(annFileName, containersNew, AnnCodecsFormat.Xml)

    ' Load and verify that there are three containers
    Dim containersThree() As AnnContainer = codecs.Load(annFileName)
    MessageBox.Show(String.Format("After Load: there should be 3 containers.  Total number of containers: {0}", containersThree.Length))
End Sub
using Leadtools;
using Leadtools.Annotations;
using Leadtools.Codecs;
using Leadtools.WinForms;

public void AnnCodecs_Save2()
{
   // create three  annotation containers
   // The first container contains a rectangle object
   AnnContainer container0 = new AnnContainer();
   AnnRectangleObject rectObj = new AnnRectangleObject();
   rectObj.Bounds = new AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel);
   rectObj.Pen = new AnnPen(Color.Blue, new AnnLength(1, AnnUnit.Pixel));
   rectObj.Brush = null;
   container0.Objects.Add(rectObj);

   // The second container contains a line object
   AnnContainer container1 = new AnnContainer();
   AnnLineObject lineObj = new AnnLineObject();
   lineObj.StartPoint = new AnnPoint(100, 100, AnnUnit.Pixel);
   lineObj.EndPoint = new AnnPoint(200, 200, AnnUnit.Pixel);
   lineObj.Pen = new AnnPen(Color.Red, new AnnLength(1, AnnUnit.Pixel));
   container1.Objects.Add(lineObj);

   // The third container contains a ellipse object
   AnnContainer container2 = new AnnContainer();
   AnnEllipseObject ellipseObj = new AnnEllipseObject();
   ellipseObj.Bounds = new AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel);
   ellipseObj.Pen = new AnnPen(Color.Blue, new AnnLength(1, AnnUnit.Pixel));
   ellipseObj.Brush = null;
   container2.Objects.Add(ellipseObj);

   // create a file to save both annotation containers
   string annFileName = Path.GetTempFileName();

   // create a new AnnCodecs class
   AnnCodecs codecs = new AnnCodecs();

   // save both AnnContainers into the stream
   codecs.Save(annFileName, container0, AnnCodecsFormat.Xml, 1, AnnCodecsSavePageMode.Overwrite);
   codecs.Save(annFileName, container1, AnnCodecsFormat.Xml, 2, AnnCodecsSavePageMode.Insert);

   // Now load both containers from the stream, and verify that there are two containers
   AnnContainer[] containersTwo = codecs.Load(annFileName);
   MessageBox.Show(String.Format("After Load: there should be 2 containers.  Total number of containers: {0}", containersTwo.Length));

   // Add another container, and save to the stream
   AnnContainer[] containersNew = new AnnContainer[containersTwo.Length + 1];
   Array.Copy(containersTwo, containersNew, containersTwo.Length);
   containersNew[2] = container2;

   codecs.Save(annFileName, containersNew, AnnCodecsFormat.Xml);

   // Load and verify that there are three containers
   AnnContainer[] containersThree = codecs.Load(annFileName);
   MessageBox.Show(String.Format("After Load: there should be 3 containers.  Total number of containers: {0}", containersThree.Length));
}
Requirements

Target Platforms

See Also

Reference

AnnCodecs Class
AnnCodecs Members
Overload List

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.